//
//  GestureTopView.swift
//  ezyform
//
//  Created by Moennig Q on 20/7/2022.
//  Copyright © 2022 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit

class GestureMiniView: UIView {
    
    var btnArray:[UIButton] = [UIButton]()
    let btnWH: CGFloat = 10//圆点宽度
    var viewWidth: CGFloat = 50//9个点所在view的宽度
    let btnImgNormal = "gesturesetting_mini_unsel"
    let btnImgSelected =  "gesturesetting_mini_sel"
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpView()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpView() {
        for i in 0...8 {
            //第几行
            let row = i / 3
            let loc = i % 3
            
            //两个button的间距
            let btnSpace = (viewWidth - 3*btnWH)/2
            let btnX = (btnWH + btnSpace) * CGFloat(loc)
            let btnY = (btnWH + btnSpace) * CGFloat(row)
            let gestureNodeBtn = UIButton(frame:CGRect(x: btnX,y: btnY,width: btnWH, height: btnWH))
            gestureNodeBtn.tag = i
            gestureNodeBtn.layer.cornerRadius = btnWH / 2
            gestureNodeBtn.clipsToBounds = true
            gestureNodeBtn.isUserInteractionEnabled = false   //不响应用户的交互。一定要加上这句
            gestureNodeBtn.setImage(UIImage(named: btnImgNormal), for: .normal)
            self.addSubview(gestureNodeBtn)
            self.btnArray.append(gestureNodeBtn)
        }
    }
    func setSelectTagArray(_ tagArray: [Int]){
        for tag in tagArray{
            if let existBtn = self.btnArray.first(where: { btn in btn.tag == tag }){
                existBtn.setImage(UIImage(named: btnImgSelected), for: .normal)
            }
        }
    }
}
